home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / batchut / strings2.zip / STRINGS1.DOC < prev   
Text File  |  1992-11-25  |  38KB  |  849 lines

  1. STRINGS.COM  (Version 1.0)             Copyright (c) 1992 
  2. -------------------------------------------------------------------------
  3.             First Published in PC Magazine September 10, 1991 (Utilities)
  4. -------------------------------------------------------------------------
  5. This documentation is for STRINGS Version 1.0
  6.  
  7.  
  8. STRINGS:
  9.         STRINGS enables batch files to manipulate strings, request and
  10. interpret user input, process files, return system information, and
  11. perform simple math by adding functions to the batch file language.
  12. Stores information in either the local or the master environment.
  13.  
  14.      Batch files are quick, simple--and frustratingly limited. They can't
  15. ask you questions or interpret your answers. They can't parse a filename,
  16. tell you how much space is left in your environment, or even perform
  17. simple math. Yet despite their shortcomings, a dozen times a day it's to
  18. batch files that we must turn for routine tasks.
  19.  
  20.      By executing STRINGS.COM from within your batch files, however, you
  21. can make .BAT files do things they could never accomplish on their own.
  22. STRINGS removes many of the restrictions imposed by the limited batch
  23. file vocabulary. For example, you'll be able to perform standard string
  24. manipulations, such as separating a filename from its extension, finding
  25. one string in another, determining the length of a string, and even
  26. reading and writing files.
  27.  
  28.      STRINGS can store its results in environment variables that other
  29. programs (or subsequent calls to STRINGS) can access. It provides simple
  30. functions that allow batch files to ask a user for input, determine
  31. exactly what he entered, and then pass that input to other programs.
  32. STRINGS even includes simple but effective math functions.
  33.  
  34. USING STRINGS
  35.  
  36.      To execute the program, either from within a batch file or from the
  37. DOS prompt, you enter STRINGS, followed by the desired command function
  38. and its necessary parameters. The full syntax is
  39.  
  40. STRINGS [/?] [/M] [/Pc] [environment var =] FUNCTION [str1][, str2][, str3]
  41.  
  42. Thus, for example, to return the left 6 characters of a string, you might
  43. enter
  44.  
  45.              STRINGS LEFT this is a string, 6
  46.  
  47.      To store the This i result you would simply insert the name of the
  48. destination environment variable, followed by an equal sign, before the
  49. command. Thus, to assign the results of this example in the environment
  50. variable VAR1, your command would be
  51.  
  52.        STRINGS VAR1 = LEFT This is a stirng, 6
  53.  
  54. STRINGS would find or create the environment variable VAR1 in the local
  55. environment and assign the value This i to it.
  56.  
  57.      STRINGS defaults to using the local command-shell environment to
  58. store environment variable results, because that is what batch files use
  59. when substituting strings for environment variables. However, by including
  60. the /M switch before the variable name, you can force STRINGS to use the
  61. system master environment instead of the local command processor
  62. environment. As will be discussed in fuller detail later, you will
  63. use this ability in establishing communications among different DOS
  64. sessions running under Windows.
  65.  
  66.      Another situation in which the /M switch comes in handy is when you
  67. "shell out" to DOS from within a running program. When a program shells
  68. out to DOS, a copy of COMMAND.COM and the accompanying environment are
  69. created. Any environment variable assignments STRINGS makes during this
  70. shelled session will be lost when you exit from DOS back into the original
  71. program, however. If you want to keep any STRINGS assignments made during
  72. a shelled session, use the /M switch.
  73.  
  74.      STRINGS provides two additional command line options. The /? switch
  75. simply displays a help list of the STRINGS function commands. These are
  76. shown in the table below - Figure 1.
  77.  
  78.      The second command line switch is /Pc. Since many strings contain
  79. spaces, by default, STRINGS uses commas instead of spaces to separate
  80. multiple command parameters. If any of the parameter strings themselves
  81. contain commas, however, you can use the /Pc switch to force STRINGS to
  82. employ any unused character as c to differentiate one string from another.
  83. Thus, for example, using /P$ changes the parse character to the dollar
  84. sign ($).
  85.  
  86.      After a parse character is found, STRINGS scans for the first nonspace
  87. character to begin the next parameter. This process has the effect of
  88. ignoring any leading spaces a parameter may have. To force STRINGS to
  89. respect leading spaces, therefore, STRINGS has been written to interpret
  90. consecutive parse characters as the beginning of a parameter.
  91.  
  92.      For example, if a string with leading spaces is to be written to a
  93. file, the line
  94.  
  95.            STRINGS WRITE c:\file.out, ,,  This line has 3 leading spaces
  96.  
  97. should be used. Without the consecutive commas, STRINGS would begin the
  98. next parameter with the letter T. Using the double parse characters,
  99. STRINGS will not append the commas to the line but will keep the proper
  100. number of spaces in the string before the word  This.
  101.  
  102.      One additional character requires special handling. DOS uses the
  103. equal sign (=) in assigning a variable name to a value. What happens,
  104. then, if the string parameter you want STRINGS to read into a variable
  105. itself contains an equal sign? You might, for example, want STRINGS to
  106. read the line 
  107.  
  108.               DEVICE=HIMEN.SYS
  109.  
  110. from your CONFIG.BAT file and assign this as VAR2.
  111.  
  112.      STRINGS handles this situation by changing the equal sign character
  113. within the string into the similar-looking but wider ASCII 205 (CDh)
  114. graphics character (=) before assigning the string to an environment
  115. variable. In this example, then, the string actually stored in the
  116. environment would then look like 
  117.  
  118.                                  VAR2=DEVICE=HIMEN.SYS
  119.  
  120.      When it reads an environment variable containing the graphics =
  121. character, STRINGS knows to make the reverse substitution of the normal
  122. equal sign. The only thing you need to be aware of is that a program
  123. other than STRINGS will not know about the need to convert the graphics
  124. equal sign back into a regular equal sign in environment variables stored
  125. by STRINGS.
  126.  
  127.      A final reminder for using STRINGS: DOS limits the length of a program
  128. command line to a maximum of 127 characters. Long strings stored with short
  129. names may run up against this limitation when interpreted.
  130.  
  131. COMMAND FUNCTIONS
  132.  
  133.      Several of the STRINGS command functions have been used illustratively
  134. above, but a more systematic description of the complete function set is
  135. in order. The functions can be divided into four main groups: (1) string
  136. manipulation; (2) file operations; (3) system functions; and (4) math
  137. functions.
  138.  
  139.      (1)   The string manipulation functions start with the LEFT and
  140. RIGHT functions. As shown in the first example, LEFT returns the first n
  141. characters of a string. RIGHT operates similarly: The first parameter
  142. you supply is the string, and the second parameter is the number of
  143. characters you want returned. In both cases, if the string is shorter
  144. than the number you specify, the entire string is returned. If the second
  145. parameter is 0, both functions return a null string.
  146.  
  147.      Assigning a null string to an environment variable removes the
  148. variable from the environment. For example, if the environment contained
  149. the variable PLAY=1234 and the command
  150.  
  151.                                        STRINGS PLAY = LEFT abcd, 0
  152.  
  153. was entered, STRINGS would erase the variable PLAY from the environment. Note
  154. that STRINGS makes no attempt to display null strings on the screen.
  155.  
  156.      The MID function is used to return a substring starting at any point
  157. within the original string. As with the LEFT and RIGHT commands, the first
  158. parameter you enter is the string itself. The second parameter is the
  159. numerical position of the starting character. The third parameter is the
  160. requested length of the string you want returned. If the starting character
  161. is higher than the length of the string, a null string is returned.
  162.  
  163.      Not surprisingly, the LENGTH function returns the length of a str